import request from '@/utils/request'
import store from '@/store/index'
/**
 * 验证码
 * @param {*} mobile 手机号码
 */
export const reqsendCode = (mobile) => {
  return request.get('/v1_0/sms/codes/' + mobile)
}
/**
 * 登录
 * @param {*} mobile 手机号码
 * @param {*} code 验证码
 */
export const reqLogin = (mobile, code) => {
  return request.post('/v1_0/authorizations', {
    mobile,
    code
  })
}
/**
 * 用户个人资料  ------ 用户个人信息
 * 带上token
 */
export const reqGetProfile = () => {
  const token = store.state.user.tokenInfo.token
  return request({
    method: 'get',
    url: '/v1_0/user/profile',
    headers: {
      Authorization: `Bearer ${token}`
    }
  })
}

/**
 * 用户页面信息
 */
export const reqGetUser = () => {
  return request({
    method: 'get',
    url: '/v1_0/user'
  })
}

/**
 * 编辑用户个人资料
 * @param {*} obj
 * { name：'',
 * gender:0/1,
 * birthday:''}
 */
export const reqUserSelf = (obj) => {
  return request({
    method: 'patch',
    url: '/v1_0/user/profile',
    data: obj
  })
}

/**
 * 用来请求新token
 * @param {*} refreshToken 用来请求新token
 */
export const reqRefreshToken = (refreshToken) => {
  return request({
    method: 'put',
    url: '/v1_0/authorizations',
    // 单独配置请求头 （只有这个接口：是用refresh_token）
    headers: {
      Authorization: `Bearer ${refreshToken}`
    }
  })
}

/**
 * 修改头像
 * @param {*} formData
 */
export const reqUpdatePhoto = (formData) => {
  return request({
    method: 'patch',
    url: '/v1_0/user/photo',
    data: formData
  })
}
